// SPDX-License-Identifier: GPL-2.0
/*
 * Device Tree Source for the Salvator-X 2nd version board with R-Car H3 ES2.0
 *
 * Copyright (C) 2015-2017 Renesas Electronics Corp.
 */

/dts-v1/;
#include "r8a7795.dtsi"
#include "salvator-xs.dtsi"

/ {
	model = "Renesas Salvator-X 2nd version board based on r8a7795 ES2.0+";
	compatible = "renesas,salvator-xs", "renesas,r8a7795";

	memory@48000000 {
		device_type = "memory";
		/* first 128MB is reserved for secure area. */
		reg = <0x0 0x48000000 0x0 0x38000000>;
	};

	memory@500000000 {
		device_type = "memory";
		reg = <0x5 0x00000000 0x0 0x40000000>;
	};

	memory@600000000 {
		device_type = "memory";
		reg = <0x6 0x00000000 0x0 0x40000000>;
	};

	memory@700000000 {
		device_type = "memory";
		reg = <0x7 0x00000000 0x0 0x40000000>;
	};
};

&du {
	clocks = <&cpg CPG_MOD 724>,
		 <&cpg CPG_MOD 723>,
		 <&cpg CPG_MOD 722>,
		 <&cpg CPG_MOD 721>,
		 <&cpg CPG_MOD 727>,
		 <&versaclock6 1>,
		 <&x21_clk>,
		 <&x22_clk>,
		 <&versaclock6 2>;
	clock-names = "du.0", "du.1", "du.2", "du.3", "lvds.0",
		      "dclkin.0", "dclkin.1", "dclkin.2", "dclkin.3";
};

&ehci2 {
	status = "okay";
};

&ehci3 {
	dr_mode = "otg";
	status = "okay";
};

&hsusb3 {
	dr_mode = "otg";
	status = "okay";
};

&sound_card {
	dais = <&rsnd_port0	/* ak4613 */
		&rsnd_port1	/* HDMI0  */
		&rsnd_port2>;	/* HDMI1  */
};

&hdmi0 {
	status = "okay";

	ports {
		port@1 {
			reg = <1>;
			rcar_dw_hdmi0_out: endpoint {
				remote-endpoint = <&hdmi0_con>;
			};
		};
		port@2 {
			reg = <2>;
			dw_hdmi0_snd_in: endpoint {
				remote-endpoint = <&rsnd_endpoint1>;
			};
		};
	};
};

&hdmi0_con {
	remote-endpoint = <&rcar_dw_hdmi0_out>;
};

&hdmi1 {
	status = "okay";

	ports {
		port@1 {
			reg = <1>;
			rcar_dw_hdmi1_out: endpoint {
				remote-endpoint = <&hdmi1_con>;
			};
		};
		port@2 {
			reg = <2>;
			dw_hdmi1_snd_in: endpoint {
				remote-endpoint = <&rsnd_endpoint2>;
			};
		};
	};
};

&hdmi1_con {
	remote-endpoint = <&rcar_dw_hdmi1_out>;
};

&ohci2 {
	status = "okay";
};

&ohci3 {
	dr_mode = "otg";
	status = "okay";
};

&rcar_sound {
	ports {
		/* rsnd_port0 is on salvator-common */
		rsnd_port1: port@1 {
			rsnd_endpoint1: endpoint {
				remote-endpoint = <&dw_hdmi0_snd_in>;

				dai-format = "i2s";
				bitclock-master = <&rsnd_endpoint1>;
				frame-master = <&rsnd_endpoint1>;

				playback = <&ssi2>;
			};
		};
		rsnd_port2: port@2 {
			rsnd_endpoint2: endpoint {
				remote-endpoint = <&dw_hdmi1_snd_in>;

				dai-format = "i2s";
				bitclock-master = <&rsnd_endpoint2>;
				frame-master = <&rsnd_endpoint2>;

				playback = <&ssi3>;
			};
		};
	};
};

&pfc {
	usb2_pins: usb2 {
		groups = "usb2";
		function = "usb2";
	};

	/*
	 * - On Salvator-X[S], GP6_3[01] are connected to ADV7482 as irq pins
	 *   (when SW31 is the default setting on Salvator-XS).
	 * - If SW31 is the default setting, you cannot use USB2.0 ch3 on
	 *   r8a7795 with Salvator-XS.
	 *   Hence the SW31 setting must be changed like 2) below.
	 *   1) Default setting of SW31: ON-ON-OFF-OFF-OFF-OFF:
	 *	- Connect GP6_3[01] to ADV7842.
	 *   2) Changed setting of SW31: OFF-OFF-ON-ON-ON-ON:
	 *	- Connect GP6_3[01] to BD082065 (USB2.0 ch3's host power).
	 *	- Connect GP6_{04,21} to ADV7842.
	 */
	usb2_ch3_pins: usb2_ch3 {
		groups = "usb2_ch3";
		function = "usb2_ch3";
	};
};

&usb2_phy2 {
	pinctrl-0 = <&usb2_pins>;
	pinctrl-names = "default";

	status = "okay";
};

&usb2_phy3 {
	pinctrl-0 = <&usb2_ch3_pins>;
	pinctrl-names = "default";

	status = "okay";
};
